home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Book Chapters / 10 - Networking / NovelNetwar / misc.c < prev    next >
Text File  |  1995-05-12  |  2KB  |  174 lines

  1. //    Various miscellaneous functions....
  2.  
  3.  
  4. #include "NovelNetwar.h"
  5.  
  6. #include <Traps.h>
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. OSErr BreakKey(void)
  15. {
  16. EventRecord        theEvent;
  17. char            theChar;
  18. int                theResult;
  19.  
  20.     theResult = false;
  21.     
  22.     if (EventAvail(keyDownMask+autoKeyMask,&theEvent))
  23.     {
  24.         theChar = theEvent.message & charCodeMask;
  25.         
  26.         if (theEvent.modifiers&cmdKey && theChar=='.')
  27.         {
  28.             theResult = true;
  29.             FlushEvents(keyDownMask+autoKeyMask,0);
  30.         }
  31.     }
  32.         
  33.     return(theResult);
  34. }
  35.  
  36.  
  37.  
  38.  
  39. OSErr ShiftKey(void)
  40. {
  41. KeyMap    theKeyMap;
  42.  
  43.     GetKeys(theKeyMap);
  44.     
  45.     if (((unsigned char *) theKeyMap)[7] & 0x01)
  46.         return(true);
  47.     else
  48.         return(false);
  49. }
  50.  
  51.  
  52.  
  53. OSErr OptionKey(void)
  54. {
  55. KeyMap    theKeyMap;
  56.  
  57.     GetKeys(theKeyMap);
  58.     
  59.     if (((unsigned char *) theKeyMap)[7] & 0x04)
  60.         return(true);
  61.     else
  62.         return(false);
  63. }
  64.  
  65.  
  66.  
  67.  
  68. OSErr CommandKey(void)
  69. {
  70. KeyMap    theKeyMap;
  71.  
  72.     GetKeys(theKeyMap);
  73.     
  74.     if (((unsigned char *) theKeyMap)[6] & 0x80)
  75.         return(true);
  76.     else
  77.         return(false);
  78. }
  79.  
  80.  
  81.  
  82.  
  83. OSErr CtrlKey(void)
  84. {
  85. KeyMap    theKeyMap;
  86.  
  87.     GetKeys(theKeyMap);
  88.     
  89.     if (((unsigned char *) theKeyMap)[7] & 0x04)
  90.         return(true);
  91.     else
  92.         return(false);
  93. }
  94.  
  95.  
  96.  
  97.  
  98. OSErr CapsLock(void)
  99. {
  100. KeyMap    theKeyMap;
  101.  
  102.     GetKeys(theKeyMap);
  103.     
  104.     if (theKeyMap[1] & 0x02)
  105.         return(true);
  106.     else
  107.         return(false);
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. void getGrayRgnRect(Rect *theRect)
  116. {
  117. RgnHandle    theGrayRgnHandle;
  118.  
  119.     SetRect(theRect,qd.screenBits.bounds.left+10,qd.screenBits.bounds.top+25,qd.screenBits.bounds.right-10,qd.screenBits.bounds.bottom-25);
  120.     
  121.     theGrayRgnHandle = GetGrayRgn();
  122.     
  123.     if (theGrayRgnHandle)
  124.         *theRect = (**theGrayRgnHandle).rgnBBox;
  125. }
  126.  
  127.  
  128.  
  129. void mystrncpy(register char *s1, register char *s2,register long n)
  130. {
  131.     if (n > 0L)
  132.     {
  133.         n--;
  134.         
  135.         while (*s2 && n--)
  136.             *s1++ = *s2++;
  137.         
  138.         *s1 = 0;
  139.     }
  140. }
  141.  
  142.  
  143.  
  144. void mystrncat(register char *s1, register char *s2,register long n)
  145. {
  146.     if (n > 0L)
  147.     {
  148.         while (*s1 && n)
  149.         {
  150.             s1++;
  151.             n--;
  152.         }
  153.         
  154.         if (n > 0L)
  155.         {
  156.             n--;
  157.             
  158.             while (*s2 && n--)
  159.                 *s1++ = *s2++;
  160.             
  161.             *s1 = 0;
  162.         }
  163.     }
  164. }
  165.  
  166.  
  167.  
  168. OSErr TrapAvailable(int theTrap)
  169. {
  170.     if (NGetTrapAddress(theTrap, OSTrap) == NGetTrapAddress(0x009F,OSTrap))
  171.         return(TRAPABSENT);
  172.     else
  173.         return(noErr);
  174. }